# web/quotes.py
#
#

__copyright__ = 'this file is in the public domain'

from gozerbot.db import db
from plugs.webserver import httpd
from plugs.quote import quotes

def handle_quotes(event):
    result = []
    for i in quotes.data:
        result.append("[%s] %s" % (i.id, i.txt))
    if not result:
        return ['no quotes', ]
    return result

def handle_quotesdb(event):
    result = []
    dbresult = db.execute(""" SELECT indx, quote FROM quotes """)
    if not dbresult:
        return ['no quotes', ]
    for i in dbresult:
        result.append("[%s] %s" % (i[0], i[1]))
    return result

if httpd:
    if not db:
        httpd.addhandler('quotes', handle_quotes)
    else:
        httpd.addhandler('quotes', handle_quotesdb)
